package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.dao.DecisionTreeDao;
import com.xbongbong.pro.domain.entity.DecisionTreeEntity;
import com.xbongbong.saas.model.DecisionTreeModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: hongxiao
 * @date: 2021-11-20 09:52
 */
@Service("decisionTreeModel")
public class DecisionTreeModelImpl implements DecisionTreeModel {

    @Resource
    private DecisionTreeDao decisionTreeDao;

    @Override
    public Integer save(DecisionTreeEntity entity) throws XbbException{
        if (entity.getId() == null || entity.getId().equals(0)) {
            return insert(entity);
        }
        return update(entity);
    }

    @Override
    public DecisionTreeEntity getByDataId(String corpid, Integer businessType, Long formId, Long dataId) {
        return decisionTreeDao.getByDataId(corpid, businessType, formId, dataId);
    }

    @Override
    public Integer insert(DecisionTreeEntity entity) throws XbbException {
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return decisionTreeDao.insert(entity);
    }

    @Override
    public Integer update(DecisionTreeEntity entity) throws XbbException {
        long now = DateUtil.getInt();
        entity.setUpdateTime(now);
        return decisionTreeDao.update(entity);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return decisionTreeDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return decisionTreeDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }
}
